package com.kuang.filter;

import com.kuang.pojo.User;
import com.kuang.util.Constants;
import com.sun.tools.javac.code.Attribute;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SysFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {

    }
//实现拦截器
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request= (HttpServletRequest) req;
        HttpServletResponse response= (HttpServletResponse) req;

        //过滤器 从session中获取用户
        User user = (User) request.getSession().getAttribute(Constants.USER_SESSION);


        if (user==null){//已经移除了或者注销了，没有登录
            response.sendRedirect("smbs/login.jsp");

        }else{
            chain.doFilter(request,response);
        }

    }

    public void destroy() {

    }
}
